<template>
  <div class="container">
    <div class="home-left">
      <ListView :list="linkList" />
    </div>
    <div class="home-right">
      <div class="right-title">
        <div class="right-title-text">
          <span>热门推荐</span>
        </div>
      </div>
      <div class="right-content">
        <div class="right-content-item" v-for="item in categoryList" @click="handleClick(item.id)">
          <img src="../assets/images/yzfc.png" alt="item.title" />
          <div class="right-content-item-text">{{ item.title }}</div>
          <!-- <div class="right-content-item-desc" style="font-size: 12px;color: #ccc;">ccc</div> -->
        </div>
        <div class="right-more">
          <router-link to="/category">
            <MoreIcon />
            查看更多
          </router-link>
        </div>  
      </div>
      
    </div>
  </div>
</template>

<script setup lang="ts">
import ListView from "@/components/ListView.vue";
import MoreIcon from "@/components/icons/MoreIcon.vue";
import { useRouter } from 'vue-router';
import { ref ,onMounted} from 'vue';
import { getCategoryListApi, getCategoryAPI } from '@/service/category/category';
import { useLinkStore } from '@/stores/linkStore';
import type { Category } from '@/service/category/type';
import gsap from 'gsap';
// 跳转
const router = useRouter();
const handleClick = async (item: number) => {
  router.push(`/category/${item}`);
 
}
interface CategoryItem extends Category {
  id: number;
  title: string;
  images:any;
}
const categoryList = ref<CategoryItem[]>([]);

onMounted( async () => {
  const res = await getCategoryListApi(1, 6);
  categoryList.value = res.data.list;

  gsap.from(".right-content", {
    y: '100%', // 从下方 100% 开始
    opacity: 0, // 从透明开始
    duration: 1, // 动画持续时间
    stagger: 0.2, // 每个项目之间的延迟
    ease: "power2.out" // 缓动效果
  });
});
// 获取图片路径
const baseUrl = import.meta.env.VITE_API_BASE_URL;
// 获取链接
const linkList = ref([]);
</script>

<style scoped lang="less">
.container {
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: space-between;
  .home-left {
    width: 720px;
  }
  .home-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    align-items: center;
    justify-content: left;
    padding: 10px;
    .right-title {
      width: 100%;
    display: flex;
    align-items: center;
    justify-content: left;
      font-weight: bold;
     padding: 5px 0 20px 0;
    }
    .right-content {
      background-color: #fff;
      border-radius: 10px;
      width: 100%;
      display: flex;
      flex-direction: wrap;
      justify-content: space-between;
      padding: 10px;
      flex-wrap: wrap;
      height: 344px;
      color: var(--color);
      .right-content-item-text {
        font-size: 14px;
        overflow: hidden; 
        width: 100%;
        height: 20px;
      }
      .right-more {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 10px 0;
        a {
          color: var(--color);
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
      .right-content-item {
        flex-basis: 33%;
        margin-bottom: 10px;
        img {
          width: 80px;
          height: 80px;
          display: block;
        }
      }
      .right-content-item:hover {
        cursor: pointer;
      }
    }
  }
}
@media (max-width: 768px) {
  .home-left {
    width: 100%;
  }
  .home-right {
    display: none;
  }
}
</style>
